<?php
$dp = new jDatePicker();
$dp->__dateFormat = "yy-mm-dd";
echo "<scr" . "ipt type=\"text/javascript\">";
$dp->generateDP("tanggal_hutang");
$dp->generateDP("tanggal_jatuh_tempo");
$dp->generateDP("tanggal_pelunasan");
echo "</scr" . "ipt>";
$dp->init();
?>

<h3 class="title-popup">Form <?php echo ($kode == "" ? "Tambah" : "Ubah"); ?> Data Hutang </h3>

<form action="<?php echo ($kode != "" ? $kode : ""); ?>" method="post" onsubmit="return save()" enctype="multipart/form-data">
    <?php
    if ($msg != "") {
        ?>
        <div class="BoxMessage Warning">Proses Gagal, <br /><?php echo $msg; ?></div>
        <?php
    }
    ?>

    <fieldset class="fldInput">

        <dl>

            <dt class="mandatory">Nama Karyawan</dt>
            <dd>
                <input class="read-only" type="text" name="nama" id="nama" value="<?php echo $nama; ?>" maxlength="40" size="50" readonly="readonly" />
                <input type="hidden" name="nik" id="nik" value="<?php echo $nik; ?>"   />
                <?php
                echo $gbkaryawan;
                ?>

            </dd>

            <dt class="mandatory">Tanggal Hutang</dt>
            <dd><input class="read-only" type="text" name="tanggal_hutang" id="tanggal_hutang" value="<?php echo $tanggal_hutang; ?>" maxlength="10" size="10" readonly="readonly"  /></dd>

            <dt class="mandatory">Tanggal Jatuh Tempo</dt>
            <dd><input class="read-only" type="text" name="tanggal_jatuh_tempo" id="tanggal_jatuh_tempo" value="<?php echo $tanggal_jatuh_tempo; ?>" maxlength="10" size="10" readonly="readonly"  /></dd>

            <dt class="mandatory">Nominal Hutang</dt>
            <dd><input type="text" name="nominal_hutang" id="nominal_hutang" value="<?php echo $nominal_hutang; ?>" maxlength="40" size="30" /></dd>

            <dt class="mandatory">Berapa Kali Cicilan?</dt>
            <dd><input type="text" name="kas_keluar_kb" id="jumlah_cicilan" value="<?php echo $jumlah_cicilan; ?>" maxlength="40" size="30" /></dd>

            <dt>Catatan</dt>
            <dd><input type="text" name="catatan" id="catatan" maxlength="200" size="30" value='<?php echo $catatan; ?>'/></dd>

            <dt>&nbsp;</dt>
            <dd>
                <ul id="note">
                    <li>Field dengan remark harus diisi.</li>
                    <li>Gunakan tombol Cari untuk field dengan property read-only.</li>
                </ul>
            </dd>
        </dl>
    </fieldset>
    <div id="box-control-save">
        <input type="hidden" name="vSave" id="vSave" value="1" />
        <input type="hidden" name="kode" id="kode" value="<?php echo $kode ?>" />
        <input type="hidden" name="vMode" value="<?php echo ($kode == "" ? "add" : "edit"); ?>" />
        <input type="submit" class="CommandButton" name="btnSubmit" value="Save" />&nbsp;
        <input type="button" class="CommandButton" value="Cancel" onclick="javascript:closeGB_();"/>
    </div>
</form>



<fieldset class="fldInput">
    <table class="GridTable" style="width: 100%;">        
        <tr>
            <td colspan="5" align="center"><h2>Data Pelunasan Hutang</h2></td>
        </tr>
        <tr>
            <td colspan="5" align="center"><b>Total Hutang</b> : <?= number_format($nominal_hutang, 0) ?> | <b>Sisa Hutang</b> : <?= number_format($sisa_hutang, 0) ?></td>           
        </tr>
    </table>
    <table class="GridTable" style="width: 100%;">        
        <form action="<?php echo ($kode != "" ? $kode : ""); ?>" method="post" enctype="multipart/form-data">   
            <fieldset class="fldInput">
                <dl>
                    <dt class="mandatory">Tanggal Pelunasan</dt>
                    <dd><input class="read-only" type="text" name="tanggal_pelunasan" id="tanggal_pelunasan" value="" maxlength="10" size="10" readonly="readonly"  /></dd>

                    <dt class="mandatory">Jumlah Bayar</dt>
                    <dd><input type="text" name="nominal_dibayarkan" id="nominal_dibayarkan" maxlength="40" size="30" /></dd>

                    <dt>Catatan</dt>
                    <dd><input type="text" name="catatan" id="catatan" maxlength="200" size="30" value=''/></dd>
                </dl>
            </fieldset>
            <div id="box-control-save">
                <input type="hidden" name="vSave" id="vSave" value="1" />
                <input type="hidden" name="kode" id="kode" value="<?php echo $kode ?>" />
                <input type="hidden" name="vMode" value="<?php echo ($kode == "" ? "add" : "edit"); ?>" />
                <input type="submit" class="CommandButton" name="btnSubmitPelunasan" value="Bayar" />&nbsp;                
            </div>
        </form>
    </tabel>
    <table class="GridTable" style="width: 100%;">        
        <thead>
            <tr class="GridHeader">
                <td>No.</td>
                <td>Tanggal Pelunasan</td>
                <td>Nominal</td>
                <td class="IDR">Catatan</td>
                <td width="5%">Remove</td>
            </tr>
        </thead>        
        <?php
        $i = 1;
        foreach ($data_pelunasan as $row) {
            echo "
                <tr>
                    <td>" . $i . "</td>                    
                    <td>" . $row->tanggal_pelunasan . "
                    <td>" . number_format($row->nominal_dibayarkan) . "</td>
                    <td>" . $row->catatan . "</td>
                    <td><a href='" . base_url("index.php/hutang/data_hutang_add/$id_hutang?hapus_pelunasan=$row->id_pelunasan") . "'>Hapus</a></td>
                </tr>
            ";
            $i++;
        }
        ?>
    </table>
</fieldset>
<script type="text/javascript">
    /*window.parent.parent.GB_hide();window.parent.parent.location.reload()*/
    function closeGB_() {
<?php echo CloseGB(true); ?>
    }
    function save() {
        var mandatory = ["nik", "nominal_hutang", "jumlah_cicilan"];
        var mandatoryName = ["Nama Karyawan", "Nominal Hutang", "Jumlah Cicilan"];

        for (var i = 0; i < mandatory.length; i++) {

            if (trimValue(document.getElementById(mandatory[i]).value) == '') {
                alert('Parameter ' + mandatoryName[i] + ' tidak boleh kosong!');
                return false;
            }
        }
        return true;
    }

    function trimValue(str) {
        var out = "";
        out = str.replace(/^\s+|\s+$/g, "");
        return out;
    }

    function _obj_fSendValue(kode, nama, elmKode, elmNama) {
        var elmk = document.getElementById("" + elmKode + "");
        var elmn = document.getElementById("" + elmNama + "");
        try {
            elmk.value = kode;
            elmn.value = nama;
        }
        catch (e) {
            alert(e.message);
        }
    }



</script>
